package com.jiyun.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig{

    public static final String QUEUE_NAME = "rider_queue";
    public static final String EXCHANGE_NAME = "rider_exchange";
    public static final String ROUTING_KEY = "rider_queue_key";

    // 创建队列
    @Bean
    public Queue riderQueue() {
        return new Queue(QUEUE_NAME);
    }

    // 创建交换机
    @Bean
    public TopicExchange riderExchange() {
        return new TopicExchange(EXCHANGE_NAME);
    }

    // 绑定队列到交换机
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(riderQueue())
                .to(riderExchange())
                .with(ROUTING_KEY);
    }
}
